<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
class StudyStudentLeave extends Model
{
    use SoftDelete;
     protected $deleteTime = false;
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        
               //按申请时间查找
               $start = input("get.add_time-start");
               $end = input("get.add_time-end");
               if ($start && $end) {
                   $where[]=["add_time","between",[$start,date("Y-m-d",strtotime("$end +1 day"))]];
               }
               //按开始时间查找
               $start = input("get.start_time-start");
               $end = input("get.start_time-end");
               if ($start && $end) {
                   $where[]=["start_time","between",[$start,date("Y-m-d",strtotime("$end +1 day"))]];
               }
        $list = self::order('id','desc')->with(['getStudent'])->where($where)->paginate($limit)->each(function (&$item){
            $item['add_time'] = date('Y-m-d H:i:s',$item['add_time']);
            $item['start_time'] = date('Y-m-d H时',$item['start_time']);
            $item['end_time'] = date('Y-m-d H时',$item['end_time']);
        });
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }

    public function getStudent()
    {
        return $this->hasOne(StudyStudentList::class, 'id', 'student_id');
    }
}
